﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Reflection;
using GLaDOSAtHomeCommunity.Properties;
using System.IO;

namespace GLaDOSAtHomeCommunity
{
    static class Program
    {
        public static readonly Dictionary<string, Game> Games = new Dictionary<string,Game>
        {
            { "df",         new Game("df", "Defense Grid", 18500, "DefenseGrid")        },          // Defense Grid
            { "kfloor",     new Game("kfloor", "Killing Floor", 1250, "KillingFloor")   },          // Killing Floor
            { "c",          new Game("c", "COGS", 26500, "cogs")                        },          // COGS
            { "rush",       new Game("rush", "RUSH", 38720, "rush")                     },          // RUSH
            { "ttori",      new Game("ttori", "Toki Tori", 38700, "tokitori")           },          // Toki Tori
            { "beat",       new Game("beat", "BIT.TRIP BEAT", 63700, "beat")            },          // BIT.TRIP BEAT
            { "kit",        new Game("kit", "1 2 3 Kick It!", 15540, "main")            },          // 1... 2... 3... Kick It!
            { "as",         new Game("as", "Audiosurf", 12900, "QuestViewer")           },          // Audiosurf
            { "twend",      new Game("twend", "TWEOTW", 15500, "main")                  },          // The Wonderful End of the World
            { "smboy",      new Game("smboy", "Super Meat Boy", 40800, "SuperMeatBoy")  },          // Super Meat Boy
            { "amnesia",    new Game("amnesia", "Amnesia", 57300, "launcher")           },          // Amnesia: The Dark Descent
            { "aaaaa",      new Game("aaaaa", "AAAAAA!!!", 15520, "main")               },          // AAAAAA!!!
            { "tb",         new Game("tb", "The Ball", 35460, "TheBall")                }           // The Ball
        };

        public readonly static List<Uri> SourceURLs = new List<Uri>()
        {
            new Uri("http://valvearg.redpointsoftware.com.au/arg_status.txt"),
            new Uri("http://stat.valvearg.redpointsoftware.com.au/arg_status.txt"),
            new Uri("http://xboxgamercard.net/valve/arg_status.txt"),
            new Uri("http://reddragoninn-rdi.com/arg_status.txt"),
            new Uri("http://www.irconan.co.uk/argstatus.txt"),
            new Uri("http://twmfcorp.com/arg_status.txt"),
            new Uri("http://182.be/arg_status.txt"),
            new Uri("http://hgs445.hostedd.com/shared/arg_status.txt"),
            new Uri("http://web366.server-drome.net/arg/arg_status.txt"),
            new Uri("http://tythal.com/argstatus.txt"),
            new Uri("http://vandevel.de/argstatus.txt")

        };
        public const string StatsURL = "http://stat.valvearg.redpointsoftware.com.au/glados_community.php?game=";

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // Set the loader for the DLLs.
            AppDomain.CurrentDomain.AssemblyResolve += Program.FindAssem;

            // Run the application.
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            catch (Exception e)
            {
                string msg = e.GetType().Name + "\r\n----------------\r\n" + e.Message + "\r\n" + e.StackTrace;
                Exception ie = e.InnerException;
                while (ie != null)
                {
                    msg += "\r\n----------------\r\n" + ie.GetType().Name + "\r\n----------------\r\n" + ie.Message + "\r\n" + ie.StackTrace;
                    ie = ie.InnerException;
                }
                ErrorForm ef = new ErrorForm(msg);
                ef.ShowDialog();
            }
        }

        static Assembly FindAssem(object sender, ResolveEventArgs args)
        {
            string simpleName = new AssemblyName(args.Name).Name;

            switch (simpleName)
            {
                case "Steam4NET":
                    return Assembly.Load(Resources.Steam4NET);
                default:
                    return null;
            }
        }
    }
}
